<template>
	<view class="uv-goods-nav">
		<view class="goods-box flex">
			<view class="flex goods-box_left">
				<view class="goods-nav-icon_item" @click="tohome">
					<uv-icon name="home" label="主页" label-pos="bottom"></uv-icon>
				</view>
				<view class="goods-nav-icon_item">

					<uv-icon v-if="isPoster" name="share" label="分享" label-pos="bottom" @click="showShare"></uv-icon>
					<uv-button v-else open-type="share" color="#FFF">
						<uv-icon name="share-fill" label="分享" label-pos="bottom"></uv-icon>
					</uv-button>
				</view>
			</view>
			<view class="flex goods-box_right">
				<view class="goods-nav-button_item">
					<uv-button type="primary" shape='circle' @click="sendmsg">私聊他</uv-button>
				</view>
				<view class="goods-nav-button_item"><uv-button shape='circle' color="#ff3600"
						@click="callphone">电话联系</uv-button>
				</view>


			</view>
		</view>
		<uv-popup ref="ref_share" mode="bottom" :round="15">
			<view class="share-popup-box">
				<view class="share-title">
					分享
				</view>
				<uv-row>
					<uv-col :span="6">
						<uv-button open-type="share" :customStyle="btncust">
							<uv-icon name="share-fill" label="分享好友" :size="40" labelPos="bottom"></uv-icon>
						</uv-button>
					</uv-col>
					<uv-col :span="6">
						<uv-button @click="handelCreateImg" :customStyle="btncust">
							<uv-icon name="photo-fill" label="生成海报" :size="40" labelPos="bottom">

							</uv-icon>
						</uv-button>
					</uv-col>


				</uv-row>
			</view>

		</uv-popup>
		<uv-popup ref="ref_pic" :round="15" mode="bottom">
			<view class="postr-box">
				<view class="title">
					<uv-text text="海报" align="center"></uv-text>
				</view>
				<view class="postr-img">
					<uv-image :customStyle="imgStyle" :src="img" mode="aspectFit" :showMenuByLongpress="true"
						width="500rpx" height="900rpx"></uv-image>
				</view>
				<uv-row>
					<uv-col :span="6">
						<uv-button icon="download" @click="downPic">保存图片</uv-button></uv-col>
					<uv-col :span="6">
						<uv-button icon="attach" @click="copy">复制内容</uv-button></uv-col>
				</uv-row>

			</view>
		</uv-popup>
		<mosowe-canvas-image ref="ref_createImg" :lists="canvelist" :height="canvas.height" :width="canvas.width"
			:imgType="canvas.imgtype" showLoading @canvasImage="_canvasImage"></mosowe-canvas-image>
	</view>
</template>

<script>
	export default {
		name: "fy-user-nav",
		props: {
			userInfo: {
				type: Object
			},
			canvelist: {
				type: Array,
				default: function() {
					return []
				}
			},
			copyText: {
				type: String,
				default: ''
			},
			isPoster: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				btncust: {
					padding: '0 5px',
					height: '100px',
					Border: 'none'
				},
				imgStyle: {
					BorderRadius: '15px',
					BoxShadow: '5px 5px 10px #888888',
				}, 
				img: '',
				canvas: {
					lists: [

					],
					height: 1350,
					width: 750,
					imgtype: 'png'
				}
			};
		},
		created() {

		},
		methods: {
			downPic() {
				wx.saveImageToPhotosAlbum({
					filePath: this.img,
					success(res) {
						uni.showToast({
							title: "已保存到相册"
						})
					},
					fail(err) {
						console.log('err', res)
					}
				})
			},
			copy() {
				uni.setClipboardData({
					data: this.copyText,
					showToast: true
				})
			},
			_canvasImage(e) {
				this.img = e
			},
			handelCreateImg() {
				this.closeShare()
				this.$refs.ref_pic.open();
				this.canvas.lists = this.canvelist
				this.$refs.ref_createImg.createCanvas();

			},
			tohome() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			showShare() {
				this.$emit("getmpwxicon",{}) 
				this.$refs.ref_share.open()
			},
			closeShare() {
				this.$refs.ref_share.close()
			},
			callphone() {
				uni.makePhoneCall({ phoneNumber: this.userInfo.phone })
			},
			sendmsg() {
				var url_parm =
					`?userid=${this.userInfo.id}&imgsrc=${this.userInfo.imgsrc}&username=${this.userInfo.name}`
				uni.navigateTo({ url: '/pages/message/signTalk' + url_parm })
			},
		}
	}
</script>

<style lang="scss">
	.postr-box {
		padding: 25rpx;

		.title {
			padding: 15rpx;
		}

		.postr-img {

			margin: 5rpx 100rpx;
		}

		.post-button {
			display: flex;
			justify-content: center;
		}

	}

	.share-popup-box {
		padding: 10px;

		.share-title {
			text-align: center;
		}
	}

	.uv-goods-nav {
		display: flex;
		position: fixed;
		width: 100%;
		bottom: 0px;
		padding: 15rpx;
		background-color: #fff;
		z-index: 900;

		.goods-box {
			flex-direction: row;
			flex: 1;
			height: 90rpx;
			background-color: #fff;

			&_left {
				justify-content: center;
				align-items: center;
				padding: 0 5px;
				width: 250rpx;

			}

			&_right {
				flex: 1;
				padding: 0 5px;
				flex-direction: row;
			}

			.goods-nav-icon_item {
				display: flex;
				flex: 1;
				position: relative;
				justify-content: center;
				align-items: center;
				flex-direction: column;
			}

			.goods-nav-button_item {
				flex: 1;
				padding: 0 5px;
				justify-content: center;
				align-items: center;
			}
		}
	}
</style>